package com.tmpt.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {

	public static String toMD5(String source) throws NoSuchAlgorithmException{
		byte[] dg = toMD5(source.getBytes());
		String r = Utils.byte2hex(dg);
		return r.toUpperCase();
	}

	public static byte[] toMD5(byte[] sourceBytes) throws NoSuchAlgorithmException{
		MessageDigest messageDigest = MessageDigest.getInstance("MD5");
		messageDigest.update(sourceBytes);
		byte[] dg = messageDigest.digest();
		return dg;
	}
	
	public static String toMD5ForApp(String source) throws NoSuchAlgorithmException{
		source = source+"There are three kinds of goals:short-term,medium-range and long-term gorls."; 
		byte[] dg = toMD5(source.getBytes());
		String r = Utils.byte2hex(dg);
		return r.toLowerCase();
	}

	public static void main(String[] args) throws NoSuchAlgorithmException {
		//.out.println(toMD5ForApp("helloworld"));
	}

}
